package com.fr.data.condition;

import com.fr.base.FRContext;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.core.Compare;
import com.fr.report.cellElement.Formula;
import com.fr.report.core.ReportCoreConstants;
import com.fr.report.core.ScriptUtils;
import com.fr.report.script.Calculator;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.parser.UtilEvalError;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ObjectCondition extends AbstractCondition
{
  private Compare compare;

  public ObjectCondition()
  {
  }

  public ObjectCondition(Compare paramCompare)
  {
    setCompare(paramCompare);
  }

  public Compare getCompare()
  {
    return this.compare;
  }

  public void setCompare(Compare paramCompare)
  {
    this.compare = paramCompare;
  }

  public String[] getDependence()
  {
    return ScriptUtils.getDependenceByCompare(this.compare);
  }

  public boolean eval(Object paramObject, Calculator paramCalculator)
  {
    if (this.compare == null)
      return true;
    Compare localCompare = getCompare();
    Object localObject = localCompare.getValue();
    if (localObject instanceof Formula)
      try
      {
        localObject = paramCalculator.eval(((Formula)localObject).getContent().substring(1));
      }
      catch (UtilEvalError localUtilEvalError)
      {
        FRContext.getLogger().log(Level.WARNING, localUtilEvalError.getMessage(), localUtilEvalError);
      }
    else if ((!(localObject instanceof String)) && (!(localObject instanceof Primitive)))
      localObject = paramCalculator.resolveVariable(localObject);
    else if ((localObject instanceof String) && (((String)localObject).startsWith("@")))
      localObject = paramCalculator.resolveVariable(localObject);
    if (localObject != null)
      try
      {
        localCompare = (Compare)localCompare.clone();
        localCompare.setValue(localObject);
      }
      catch (CloneNotSupportedException localCloneNotSupportedException)
      {
        FRContext.getLogger().log(Level.WARNING, localCloneNotSupportedException.getMessage(), localCloneNotSupportedException);
      }
    return localCompare.eval(paramObject);
  }

  public boolean equals(Object paramObject)
  {
    if ((paramObject == null) || (!(paramObject instanceof ObjectCondition)))
      return false;
    ObjectCondition localObjectCondition = (ObjectCondition)paramObject;
    return ComparatorUtils.equals(localObjectCondition.getCompare(), getCompare());
  }

  public String toString()
  {
    return "currentValue " + ReportCoreConstants.conditionToString(getCompare());
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if ((paramXMLableReader.isChildNode()) && ((("Compare".equals(paramXMLableReader.getTagName())) || (paramXMLableReader.getTagName().equals("Condition")))))
    {
      this.compare = new Compare(0, "");
      paramXMLableReader.readXMLObject(this.compare);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if (getCompare() != null)
      getCompare().writeXML(paramXMLPrintWriter);
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ObjectCondition localObjectCondition = (ObjectCondition)super.clone();
    if (this.compare != null)
      localObjectCondition.compare = ((Compare)this.compare.clone());
    return localObjectCondition;
  }
}